Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordering organizations and users by name #49

Closed
wants to merge 45 commits into from
Closed

Ordering organizations and users by name #49

wants to merge 45 commits into from

Conversation

thibaultmeyer
Copy link
Contributor

Relative to the issue #3845, this Pull Request add modifications to ordering by name Organizations and User Accounts.

It's more user friendly and make search more easy when organizations and user accounts are ordered by name rather than last update datetime.

I added new function GetUsersByIDs to decrease the number of SQL queries by using IN predicate rather than just running 1 SQL query per users.

@codecov-io
Copy link

codecov-io commented Nov 3, 2016

Current coverage is 2.24% (diff: 0.00%)

Merging #49 into master will increase coverage by 0.03%

@@            master       #49   diff @@
========================================
  Files           31        32     +1   
  Lines         7508      7530    +22   
  Methods          0         0          
  Messages         0         0          
  Branches         0         0          
========================================
+ Hits           166       169     +3   
- Misses        7326      7344    +18   
- Partials        16        17     +1   

Powered by Codecov. Last update a0e54c0...047eefc

@tboerger tboerger added this to the 1.0.0 milestone Nov 3, 2016
@tboerger tboerger added the type/enhancement An improvement of existing functionality label Nov 3, 2016
Copy link
Member

@tboerger tboerger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor revert of changes.

@@ -15,7 +15,6 @@
<table class="ui very basic striped table">
<thead>
<tr>
<th>ID</th>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep that, this is an admin view and I would print there as much information as possible.

Copy link
Contributor Author

@thibaultmeyer thibaultmeyer Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but trust me, when you have more than 1029 users (we use it in corporate environment), ID is just an annoyance, take a lot of place because the website CSS theme is not fluid and is useless to do admin maintenance tasks.

are you sure you want ID come back ?

here a screen :

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proper listing is a different story, but I would like to keep this information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

@thibaultmeyer thibaultmeyer Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tboerger Done. "ID" column restored

@@ -15,7 +15,6 @@
<table class="ui very basic striped table">
<thead>
<tr>
<th>ID</th>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@@ -18,7 +18,6 @@
<table class="ui very basic striped table">
<thead>
<tr>
<th>ID</th>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@DblK
Copy link
Member

DblK commented Nov 3, 2016

Can you rebase it?

@thibaultmeyer
Copy link
Contributor Author

You could choose "Rebase and Merge" during the merge process : https://github.com/blog/2243-rebase-and-merge-pull-requests

@@ -495,7 +499,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos
repos := make([]*Repository, 0, pageSize)
// FIXME: use XORM chain operations instead of raw SQL.
if err = x.Sql(fmt.Sprintf(`SELECT repository.* FROM repository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to do raw SQL-query here?

Copy link
Contributor Author

@thibaultmeyer thibaultmeyer Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, but this code is not part of the current pull request. It could be a part of another one (eg : rewrite and optimize all SQL queries)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you're making that line better, you could just as well make it even better 😄 Saves us another PR 👍

Copy link
Contributor Author

@thibaultmeyer thibaultmeyer Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer 1 PR = 1 problem solved. This is more simple for everyone and easily to review.

I will replace all raw queries on model files with XORM chain operations in another PR.

@@ -507,7 +511,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos
}

results, err := x.Query(fmt.Sprintf(`SELECT repository.id FROM repository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@@ -534,7 +538,7 @@ func (org *User) GetUserMirrorRepositories(userID int64) ([]*Repository, error)

repos := make([]*Repository, 0, 10)
if err = x.Sql(fmt.Sprintf(`SELECT repository.* FROM repository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

sess := x.Where("uid=?", uid)
sess := x.
Join("LEFT", "user", `"org_user".org_id="user".id`).
Where("uid=?", uid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be "org_user.uid=?" no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seem correct, Here we want organizations ordered by name, and in GOGS, organization are just a simple user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant in the Where-clause, since it's a JOIN 🙂

Copy link
Contributor Author

@thibaultmeyer thibaultmeyer Nov 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the field uid only exists on the table org_user, the WHERE clause is good. But if you wan't I can add "org_user.uid=?" ?? in all cases it will working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better be safe than sorry, and consistent (also "org_id" is only in org_user but is explicitly listed.
BTW, I don't think you need to quote "org_user" and "user"...)

@@ -298,12 +296,16 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
// GetOrgUsersByUserID returns all organization-user relations by user ID.
func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) {
ous := make([]*OrgUser, 0, 10)
sess := x.Where("uid=?", uid)
sess := x.
Join("LEFT", "user", `"org_user".org_id="user".id`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No JOIN should be needed here, as user id is already in the OrgUser table ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                           Table "public.org_user"
  Column   |  Type   |                       Modifiers                       
-----------+---------+-------------------------------------------------------
 id        | integer | not null default nextval('org_user_id_seq'::regclass)
 uid       | bigint  | 
 org_id    | bigint  | 
 is_public | boolean | 
 is_owner  | boolean | 
 num_teams | integer | 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Join is needed to order by Name

@strk strk modified the milestones: 1.1.0, 1.0.0 Nov 6, 2016
@@ -453,6 +455,8 @@ func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team,
return teams, e.Where("team_user.org_id = ?", org.ID).
And("team_user.uid = ?", userID).
Join("INNER", "team_user", "team_user.team_id = team.id").
Join("INNER", "user", `"user".id=team_user.uid`).
Copy link
Contributor

@andreynering andreynering Nov 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. Ideally, we should not quote column names. Quoting is different between different databases. PostgreSQL uses ", MySQL uses `, etc. Where this is necessary, I think using this Xorm function should work.

Same for other SQLs.

Copy link
Member

@lunny lunny Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XORM will use as the uniform quote and will replace it as database's self quote. So just use,

Join("INNER", "user", "`user`.id=team_user.uid").

}
org.Members, _ = GetUsersByIDs(ids)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why ignore the errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cause in all cases GetUsersByIDs return an array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if get users failed, we should return error to external of function. I think this should be

org.members, err = GetUsersByIDs(ids)
return err

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, always return errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -453,6 +455,8 @@ func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team,
return teams, e.Where("team_user.org_id = ?", org.ID).
And("team_user.uid = ?", userID).
Join("INNER", "team_user", "team_user.team_id = team.id").
Join("INNER", "user", `"user".id=team_user.uid`).
Asc("user.name").
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need quote on user too

bkcsoft
bkcsoft previously approved these changes Nov 9, 2016
ids[i] = ou.Uid
}
org.Members, err = GetUsersByIDs(ids)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need, just return err...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you right. Fixed

@thibaultmeyer thibaultmeyer self-assigned this Nov 9, 2016
@codecov-io
Copy link

codecov-io commented Nov 9, 2016

Current coverage is 3.13% (diff: 0.00%)

Merging #49 into master will decrease coverage by <.01%

@@            master       #49   diff @@
========================================
  Files           33        33          
  Lines         7823      7841    +18   
  Methods          0         0          
  Messages         0         0          
  Branches         0         0          
========================================
  Hits           246       246          
- Misses        7557      7575    +18   
  Partials        20        20          

Powered by Codecov. Last update 145648a...90b4883

@thibaultmeyer thibaultmeyer dismissed tboerger’s stale review November 10, 2016 06:49

ID column restored on admin console

if !all {
// Only show public organizations
sess.And("is_public=?", true)
}
err := sess.Find(&ous)
err := sess.
Asc("name").
Copy link
Member

@lunny lunny Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this should be

Asc("`user`.name")`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@lunny
Copy link
Member

lunny commented Nov 10, 2016

something wrong. @joubertredrat

@thibaultmeyer
Copy link
Contributor Author

Yeah i dont know why... I have just rebase to avoid multiple commit. Git show get right commit but github just explode. I will recreate PR within few minutes

@thibaultmeyer
Copy link
Contributor Author

thibaultmeyer commented Nov 10, 2016

Something goes wrong with rebase, I close this issue, delete GOGS repos and fork Gitea. I will re-create PR without few hours

@lunny lunny removed this from the 1.1.0 milestone Nov 10, 2016
@joubertredrat
Copy link
Contributor

joubertredrat commented Nov 10, 2016

@lunny strange, I don't have relation with this PR and my commit listed already have PRs in #5 and #54

@0xBAADF00D for me was same, was necessary to remove gogs fork and make new fork from Gitea

@tboerger tboerger added reviewed/invalid and removed type/enhancement An improvement of existing functionality labels Nov 11, 2016
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
@delvh delvh added issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea and removed reviewed/invalid labels Oct 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea
Projects
None yet
Development

Successfully merging this pull request may close these issues.